// File Name: usart_ctrl.c
// Author: kukukukuku~
// Date: 2024-12-21

#include "apm32f00x_usart.h"
#include "./USART/inc/usart_ctrl.h"

/**
 * @brief   USART串口发送数据
 * @param   data:       数据源
 * @param   dataLen:    数据个数
 * @retval  None
 * @note    None
*/
void usart_usart_send_data(const uint8_t * const data, const uint16_t dataLen)
{
    if(data == NULL || dataLen == 0)
        return;
    
    for(uint16_t i = 0; i < dataLen; i++)
    {
        while(!USART_ReadStatusFlag(USART_USART, USART_FLAG_TXC));
        USART_TxData8(USART_USART, data[i]);
    }
    
    while(!USART_ReadStatusFlag(USART_USART, USART_FLAG_TXC));
}


/**
 * @brief   USART串口接收数据
 * @param   None
 * @retval  接收到的数据
 * @note    None
*/
uint8_t usart_usart_receive_data(void)
{
    return USART_RxData8(USART_USART);
}
